<?php namespace App\Http\Controllers;

use App\Http\Requests\Contact;
use Auth;
use Request;
use Illuminate\Support\Facades\Input;
use Laracasts\Flash\Flash;
use App\User as User;

class HomeController extends Controller {

	/*
	|--------------------------------------------------------------------------
	| Home Controller
	|--------------------------------------------------------------------------
	|
	| This controller renders your application's "dashboard" for users that
	| are authenticated. Of course, you are free to change or remove the
	| controller as you wish. It is just here to get your app started!
	|
	*/

	/**
	 * Create a new controller instance.
	 *
	 * @return void
	 */
	// public function __construct()
	// {
	// 	$this->middleware('auth');
	// }

	/**
	 * Show the application dashboard to the user.
	 *
	 * @return Response
	 */
	public function index()
	{
		return view('home.index');
	}

	public function about()
	{
		return view('home.aboutus');
	}

	public function contact()
	{
		return view('home.contact');
	}

	public function store(Contact $request)
	{
		\Mail::send('home.contact',
	        array(
	            'name' => $request->get('name'),
	            'email' => $request->get('email'),
	            'user_message' => $request->get('message')
	        ), function($message)
			    {
			        $message->from('sheenajayson27@gmail.com');
			        $message->to('sheenajayson27@gmail.com', 'Admin')->subject('SEC Alumni Feedback');
			    });
		return \Redirect::route('contact');
	}

	public function account()
	{
		return view('home.account');
	}

	public function update()
	{
		return view('home.updateprofile');
	}

	public function postupdate()
	{
		$details = Input::all();
		$user = User::find(Auth::user()->id)->update($details);

		Flash::message('Update successful!');
		return redirect('/account');
	}

	public function search()
	{
		return view('home.search');
	}

	public function dosearch()
	{
		$keyword = Input::get('keyword');
		$results = User::where('first_name', 'LIKE', '%'.$keyword.'%')->orWhere('last_name', 'LIKE', '%'.$keyword.'%')->get();
		return view('home.searchresult', compact('keyword', 'results'));	
	}
}
